package dao

import (
	"netdisk/config"
	"netdisk/models"
	"xorm.io/xorm"
)

var (
	DB *xorm.Engine
)

func InitMySQL() (err error) {
	DB, err = xorm.NewEngine("mysql", config.DSN)
	if err != nil {
		return
	}

	//同步数据库表结构
	//DB.ShowSQL(true)
	err = DB.Sync2(new(models.Chunk), new(models.File), new(models.FileShare), new(models.FileShareGroup), new(models.Role), new(models.Thumbnail), new(models.User), new(models.UserFile), new(models.UserStorage), new(models.UserToken))
	return DB.DB().Ping()
}
func Close() {
	err := DB.Close()
	if err != nil {
		return
	}
}
